<template>
	<view class="userset">
		<view class="user-set-list">
			<view class="user-set-list-item" @click="toMyAddress()">
				<view class="user-set-list-item-left">我的收货地址</view>
				<view class="user-set-list-item-right">
					<image src="/static/images/rightmore.png" mode=""></image>
				</view>
			</view>
			<view class="user-set-list-item" @click="toModifyPassword()">
				<view class="user-set-list-item-left">修改登录密码</view>
				<view class="user-set-list-item-right">
					<image src="/static/images/rightmore.png" mode=""></image>
				</view>
			</view>
			<view class="user-set-list-item" @click="toSetPayCode()">
				<view class="user-set-list-item-left" v-if="user.is_pay_code_set==1||user.is_pay_code_set==true">修改交易密码</view>
				<view class="user-set-list-item-left" v-else>设置交易密码</view>
				<view class="user-set-list-item-right">
					<image src="/static/images/rightmore.png" mode=""></image>
				</view>
			</view>
			<view class="user-set-list-item">
				<view class="user-set-list-item-left">手机号</view>
				<view class="user-set-list-item-right">
					<view class="user-phone" v-if="user">{{ user.phone }}</view>
				</view>
			</view>
			<!-- <view class="user-set-list-item">
				<view class="user-set-list-item-left">版本升级</view>
				<view class="user-set-list-item-right">
					<view class="wap-edition">当前版本：1.3.0</view>
				</view>
			</view> -->
			<!-- <view class="user-set-list-item">
				<view class="user-set-list-item-left">关于我们</view>
				<view class="user-set-list-item-right">
					<image src="/static/images/rightmore.png" mode=""></image>
				</view>
			</view> -->
		</view>
		<view class="sign-out" @click="signOut()">退出登录</view>
	</view>
</template>

<script>
	const getDefaultState = () => {
		return {
			wxCode: null,
			inviteString: null,
			inviteCode: null,
			inviteProductId: null,
			accessToken: null, //获取本地存储的 access_token
			accessTokenRefreshAt: null, //获取本地存储的刷新 access_token_refresh_at
			accessTokenExpiredAt: null, //获取本地存储的到期 access_token_expired_at
			phoneNum: null,
			openid: null,
			unionid: null
		}
	}
	import store from "store";
	import { mapGetters,mapMutations,mapActions } from 'vuex'
	import { getUser } from "api/userApi"
	export default {
		store,
		data(){
			return {
				
			}
		},
		computed: {
			...mapGetters(['user'])
		},
		async onShow(){
			await this.getUser()
		},
		methods:{
			...mapMutations([
				'resetState',
				'setToken',
				'setUser',
				'resetAddress'
			]),
			...mapActions([
				'login'
			]),
			async getUser(){
				let response =  await getUser()
				this.setUser(response)
			},
			toMyAddress(){
				uni.navigateTo({
					url:'/packs/pages/address/index'
				})
			},
			toModifyPassword(){
				uni.navigateTo({
					url:'/packs/pages/modifyPassword/modifyPassword?type=1'
				})
			},
			toSetPayCode(){
				if(this.user.is_pay_code_set){
					uni.navigateTo({
						url:'/packs/pages/userset/setpaycode?type=modify'
					})
				}else{
					uni.navigateTo({
						url:'/packs/pages/userset/setpaycode'
					})
				}
				
			},
			signOut(){
				uni.clearStorage()
				this.resetState(getDefaultState())
				this.setUser(null)
				this.resetAddress()
				uni.navigateBack({})
			}
			
		}
	}
</script>

<style lang="scss" scoped>
	page{
		background: #FFFFFF;
	}
	.userset{
		padding-top: 20rpx;
	}
	.user-set-list-item{
		display: flex;
		align-items: center;
		justify-content: space-between;
		height: 88rpx;
		padding: 0 32rpx;
		border-bottom: 1rpx solid #E5E5E5;
	}
	.user-set-list-item-left{
		font-size: 26rpx;
		font-weight: 400;
		color:#555555;
	}
	.user-set-list-item-right{
		>image{
			display: block;
			width:32rpx;
			height: 32rpx;
		}
	}
	.user-phone,.wap-edition{
		font-size: 26rpx;
		font-weight: 400;
		color:#555555;
		margin-right: 15rpx;
	}
	.sign-out{
		width: 614rpx;
		height: 84rpx;
		background: linear-gradient(146deg, #FFDA55 0%, #FEBF05 100%);
		border-radius: 42rpx;
		margin: 150rpx auto;
		font-size: 32rpx;
		font-family: PingFangSC-Medium, PingFang SC;
		font-weight: 500;
		color: #FFFFFF;
		letter-spacing: 2rpx;
		display: flex;
		align-items: center;
		justify-content: center;
	}
	
</style>
